//
//  ZHStatusUserViewModel.swift
//  ZHWeibo
//
//  Created by user on 15/12/9.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit 

class ZHStatusUserViewModel: NSObject {
    //拥有模型属性
    var userModel:ZHStatusModel?
    //重载构造方法
    init(statusModel: ZHStatusModel){
        super.init()
        self.userModel = statusModel
    }
    
    //只读属性----转发数
    var retweetCountStr: String? {
        let  count: String = getCountString(self.userModel?.reposts_count ?? 0, defaulTitle: "转发")
        return count
    }
    var commentCountStr: String? {
        let  count: String = getCountString(self.userModel?.comments_count ?? 0, defaulTitle: "评论")
        return count
    }
    var attitudeCountStr: String? {
        let  count: String = getCountString(self.userModel?.attitudes_count ?? 0, defaulTitle: "赞")
        return count
    }
    
    
    private func getCountString(count: Int, defaulTitle: String) -> String {
        if count > 0 {
            // 小于1万显示原数据
            if count < 10000 {
                return "\(count)"
            }else {
                let result = CGFloat(count / 1000) / 10
                let resultStr = "\(result)万"
                
                if resultStr.containsString(".0") {
                    return resultStr.stringByReplacingOccurrencesOfString(".0", withString: "")
                }
                return resultStr
            }
        }
        return defaulTitle
    }

    
    //只读属性----VIP
    var vipImage:UIImage? {
        //首先判断是否幼稚没有值的话,就返回
        guard let rank = userModel?.user?.mbrank else {
            return nil
        }
        //根据rank获取不同的图片
        if rank > 0 && rank < 7 {
            return UIImage(named: "common_icon_membership_level\(rank)")
        }
        return nil
    }
    //只读属性----认证图标
    var verIdentifierImage:UIImage? {
        //判断是否能够获取到
        guard let ver = userModel?.user?.verified else {
            return nil
        }
        //根据不同的等级获取不同的Image
        switch ver {
        case 1:
            return UIImage(named: "avatar_vip")
        case 2,3,5:
            return UIImage(named: "avatar_enterprise_vip")
        case 220:
            return UIImage(named: "avatar_grassroot")
        default:
            return nil
        }
    }
}

// MARK: - 获取微博发布者的相关信息
extension ZHStatusUserViewModel{
    
    //网络请求
    
}